#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 15;

ll n, m;
ll a[N], b[N];
ll extgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  ll d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
ll inv(ll a, ll b) {
  ll x, y;
  extgcd(a, b, x, y);
  x %= b;
  if (x < 0) x += b;
  return x;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i] >> b[i];
  ll M = 1;
  rep(i, 1, n) M *= a[i];
  ll res = 0;
  rep(i, 1, n) {
    ll m = M / a[i];
    ll im = inv(m % a[i], a[i]);
    res = (res + (__int128_t)b[i] * m % M * im % M) % M;
  }
  cout << res;
  return 0;
}